<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<input type="text" name="" id="" value="" />
		<button>跳转s</button>
		<button>跳转</button>
		<button>跳转22</button>
		<progress value="50" height="20px" width="200px" max="200"></progress>
		
		<script type="text/javascript">
			
			var btn = document.getElementsByTagName("button");
			var Input=document.getElementsByTagName("input")[0];
			var progess=document.getElementsByTagName("progress")[0];
			
			btn[0].onclick=function(){
				var inputValue=Input.value;
				window.location.href="b.html?keyword="+inputValue;
				
				
			}
			btn[1].onclick=function(){
				//前进
				var inputValue=Input.value;
				var arr={
					arr:[1,2,3,4]
					};
				arr=JSON.stringify(arr)
				localStorage.setItem("keyword",arr);
				
			}
			btn[2].onclick=function(){
				var inputValue=Input.value;
				var d = new Date();
				d.setTime(d.getTime()+60*1000)
				console.log(d.toGMTString())
				document.cookie="username="+inputValue+";Expires="+d.toGMTString();
			}
			
			var xhr=new XMLHttpRequest();
			var src="http://hao552.gitee.io/text-dd/DJ Daniel Kim - Pop Danthology 2012.mp3";
			xhr.open("get",src,true);
			
			xhr.send();
			
			xhr.addEventListener("readystatechange",function(e){
				
				var res=e.target;
				if(res.readyState==4){
					if(res.state==200){
						alert("成功");
					}
				}
			})
			
			
			xhr.addEventListener("progress",function(e){
				console.log(e)
				
			})
			
			
			xhr.onprogress=function(event){
				if(event.lengthComputable){
//					var percentComplete=(event.loaded/event.total)*100+""
					
					progess.setAttribute("value",event.loaded);
					progess.setAttribute("max",event.total);
					
				}
			}
			//监听完成下载
			
			xhr.onload=function(event){
				
				
				//得到二进制类型文件后进行解码
				var data=xhr.response;
				console.log(data);
				AudioContext.decodeAudioData(data,function(buffer){
					//创建内存音频资源
					var source=AudioContext.createBufferSource();
					source.buffer=buffer;
					//链接
					source.connect(AudioContext.destination);
					//循环
					source.loop=true;
					//播放
					source.start();
				},function(err){
					console.log(err);
				})
			}
			
			
			
		</script>
		
	</body>
</html>
